//
//  SonListModel.swift
//  Pods
//
//  Created by eme on 2017/4/10.
//
//

import UIKit
import SwiftyJSON
import ModelProtocol

class SonListModel: ModelProtocol {
    
    // MARK: Declaration for string constants to be used to decode and also serialize.
    internal let kSonListPptremarkKey: String = "pptremark"
    internal let kSonListPpturlKey: String = "ppturl"
    internal let kSonListSonListKey: String = "sonList"
    internal let kSonListFpptidKey: String = "fpptid"
    internal let kSonListPptnameKey: String = "pptname"
    internal let kSonListPptlevelKey: String = "pptlevel"
    internal let kSonListPptdelflagKey: String = "pptdelflag"
    internal let kSonListPptimgKey: String = "pptimg"
    internal let kSonListAppcodeKey: String = "appcode"
    internal let kSonListPptypeKey: String = "pptype"
    internal let kSonListPptorderKey: String = "pptorder"
    internal let kSonListPptidKey: String = "pptid"
    
    
    // MARK: 属性
    var pptremark: String
    var ppturl: String
    var sonList: [SonListModel]
    var fpptid: Int
    var pptname: String
    var pptlevel: Int
    var pptdelflag: String
    var pptimg: String
    var appcode: String
    var pptype: String
    var pptorder: Int
    var pptid: Int
    var customIndex = -1
    var isclicked = 0
    
    // MARK: 实现MikerSwiftJSONAble 协议， 解析json数据
    required  init?(json: JSON) {
        pptremark = json[kSonListPptremarkKey].stringValue
        ppturl = json[kSonListPpturlKey].stringValue
        sonList = []
        if let items = json[kSonListSonListKey].array {
            for item in items {
                if let sonListModel = SonListModel(json: item){
                    sonList.append(sonListModel)
                }
            }
        } else {
            sonList = []
        }
        fpptid = json[kSonListFpptidKey].intValue
        pptname = json[kSonListPptnameKey].stringValue
        pptlevel = json[kSonListPptlevelKey].intValue
        pptdelflag = json[kSonListPptdelflagKey].stringValue
        pptimg = json[kSonListPptimgKey].stringValue
        appcode = json[kSonListAppcodeKey].stringValue
        pptype = json[kSonListPptypeKey].stringValue
        pptorder = json[kSonListPptorderKey].intValue
        pptid = json[kSonListPptidKey].intValue
        
    }
    
    
    /**
     Generates description of the object in the form of a NSDictionary.
     - returns: A Key value pair containing all valid values in the object.
     */
    internal func dictionaryRepresentation() -> [String : AnyObject ] {
        
        var dictionary: [String : AnyObject ] = [ : ]
        
        dictionary.updateValue(pptremark as AnyObject, forKey: kSonListPptremarkKey)
    
    
        dictionary.updateValue(ppturl as AnyObject, forKey: kSonListPpturlKey)
        
        if sonList.count > 0 {
            var temp: [AnyObject] = []
            for item in sonList {
                temp.append(item.dictionaryRepresentation() as AnyObject)
            }
            dictionary.updateValue(temp as AnyObject, forKey: kSonListSonListKey)
        }
        
        dictionary.updateValue(fpptid as AnyObject, forKey: kSonListFpptidKey)
    
    
        dictionary.updateValue(pptname as AnyObject, forKey: kSonListPptnameKey)
    
    
        dictionary.updateValue(pptlevel as AnyObject, forKey: kSonListPptlevelKey)
    
    
        dictionary.updateValue(pptdelflag as AnyObject, forKey: kSonListPptdelflagKey)
    
    
        dictionary.updateValue(pptimg as AnyObject, forKey: kSonListPptimgKey)
    
    
        dictionary.updateValue(appcode as AnyObject, forKey: kSonListAppcodeKey)
    
    
        dictionary.updateValue(pptype as AnyObject, forKey: kSonListPptypeKey)
    
    
        dictionary.updateValue(pptorder as AnyObject, forKey: kSonListPptorderKey)
    
    
        dictionary.updateValue(pptid as AnyObject, forKey: kSonListPptidKey)
        
        return dictionary
    }
    
    
}
